package 寒假刷题;

public class 仅仅反转字母 {
    public String reverseOnlyLetters(String s) {
        char[] chars = s.toCharArray();
        int i = 0,j = s.length()-1;
        while (i<j){
            if (!Character.isLetter(chars[i])){
                i++;
                continue;
            }
            if (!Character.isLetter(chars[j])){
                j--;
                continue;
            }
            char temp = chars[i];
            chars[i] = chars[j];
            chars[j] = temp;
            i++;
            j--;
        }
        return new String(chars);
    }
}
